//
// Created by ta&to on 2022/10/9.
//

#ifndef TCPSERVER_TCP_HANDLER_H
#define TCPSERVER_TCP_HANDLER_H
#include "hash_util.h"
#include "tcp_config.h"
#include "tcp_socket.h"
#include "tcp_request.h"

typedef struct tcp_handler_s tcp_handler_t;
typedef struct tcp_event_context_control_s tcp_event_context_control_t;
typedef struct tcp_rep_pak_s tcp_rep_pak_t;
typedef struct tcp_inner_request_before_facade_s tcp_inner_request_before_facade_t;
typedef struct tcp_inner_request_after_facade_s tcp_inner_request_after_facade_t;
typedef struct tcp_inner_req_status_pkg_s tcp_inner_req_status_pkg_t;
typedef void (*tcp_callback_func)(struct tcp_socket_event_loop_s *hset, tcp_inner_req_status_pkg_t *pkg);

struct tcp_handler_s{
    tcp_callback_func func;
};
struct tcp_event_context_control_s {
    tcp_handler_t *func_handler;
};
struct tcp_rep_pak_s{
    int fd;
    struct tcp_socket_event_loop_s *hset;
    struct tcp_event_context_control_s *hctx;
};
typedef struct tcp_pool_s tcp_pool_t;
struct tcp_pool_s{
    pthread_mutex_t tcp_mut_lock;
    pthread_rwlock_t tcp_rw_lock;
};
struct tcp_inner_request_before_facade_s{
#ifdef SOCKET_SERVER_SELECT
    int n;
#endif
    int fd;
    struct tcp_socket_event_loop_s *hset;
};
struct tcp_inner_request_after_facade_s{
    int fd;
    log_t *logs;
    int status;
    struct tcp_socket_event_loop_s *hset;
};
struct tcp_inner_req_status_pkg_s{
    int fd;
    int status;
    dts data;
};
extern log_t global_logt;
extern thread_pool_t global_tpt;
extern tcp_pool_t global_tcp;

void _init_tcp();
#ifdef SOCKET_SERVER_SELECT
void _tcp_socket_callback(struct tcp_socket_event_loop_s *hset, int fd, int n);
#else
void _tcp_socket_callback(struct tcp_socket_event_loop_s *hset, int fd);
#endif
#endif //TCPSERVER_TCP_HANDLER_H
